<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script>
        /*
            for in 循环

        */

        var user={
            userName:'trump',
            passwrod:'202011111',
            vote:function()
            {
                console.log(this.userName,"投了自己一票");
            }
        };
        console.log("通过.符号取值=>",user.userName);
        console.log("直接[]取值=>",user['userName']);
        var u='userName';
        console.log("直接[]取值方式2=>",user[u]);


        for(var k in user)  //循环出来的k是对象的名字(字符串)
        {
            console.log(k);  //属性名
            console.log(user[k]);   //属性值
        }

        var users=[
            {username:'trump',ad:'美国前任总统',vote:214},
            {username:'biden',ad:'美国现任总统',vote:300},
            {username:'奥巴马',ad:'美国前前任总统',vote:450},

        ]
        for(var key in users)
        {
            var ur=users[key];
            document.write(ur.username+' '+ur.ad+' '+ur.vote+'<br/>')
        }

        
    </script>
</head>
<body>
    
</body>
</html>